//
//  MangementCell.m
//  qunfa
//
//  Created by Admin on 2017/8/11.
//  Copyright © 2017年 cuixiaocun. All rights reserved.
//

#import "MangementCell.h"

@implementation MangementCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //横线
        
        NSArray*leftArr =@[@"时间",@"标题",@"详情",@"推广人数",@"推广地区",@"推广性别",@"推广选项",@"",@"",@"",@"",@"",];
        NSArray*leftImgArr =@[@"",@"",@"",@"icon_renshu",@"icon_diqu",@"icon_sex",@"icon_xuanxiang",@"",@"",@"",];

        NSArray*rightArr =@[@"",@"",@"",@"",@"",@"",@"",@"",];
        for (int i=0; i<8; i++){
            //背景
            UIView *bgview =[[UIView alloc]init];
            bgview.tag =300+i;
            bgview.backgroundColor =[UIColor whiteColor];
            [self addSubview:bgview];
            bgview.frame =CGRectMake(0,100*i*Width, CXCWidth, 100*Width);

            //左图片
            UIImageView  *jiantou =[[UIImageView alloc]initWithFrame:CGRectMake(32*Width,20*Width ,40*Width , 40*Width)];
            [bgview addSubview:jiantou];
            [jiantou setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",leftImgArr[i]]]];
            

            UILabel* leftLabe = [[UILabel alloc]initWithFrame:CGRectMake(100*Width,20*Width ,200*Width , 40*Width)];
            leftLabe.text = leftArr[i];
            leftLabe.font = [UIFont systemFontOfSize:15];
            leftLabe.textColor = BlackColor;
            [bgview addSubview:leftLabe];
            //右边显示
            UILabel* rightLabel = [[UILabel alloc]init];
            rightLabel.text = rightArr[i];
            rightLabel.frame =CGRectMake(250*Width ,0, 475*Width,82*Width );
            rightLabel.textAlignment=NSTextAlignmentRight;
            rightLabel.tag =200+i;
            rightLabel.font = [UIFont systemFontOfSize:14];
            rightLabel.textColor = BlackColor;
            [bgview addSubview:rightLabel];
            //分割线
            UIImageView*xian =[[UIImageView alloc]init];
            xian.backgroundColor =BGColor;
            [bgview addSubview:xian];
            xian.frame =CGRectMake(0,98.5*Width, CXCWidth, 1.5*Width);
            if (i==0) {

                bgview.backgroundColor =BGColor;
                leftLabe.textColor =TextGrayColor;
                leftLabe.width =500*Width;
                _timeLabel =leftLabe;
                _timeLabel.frame =CGRectMake(30*Width, 0, 650*Width, 0);

                
            }else if(i==1) {
                
                _titleLabel =leftLabe;
                
                _statusLabel=rightLabel;

                _pushBtn =[[UIButton alloc]initWithFrame:CGRectMake(500*Width,  0, 230*Width, 100*Width)];
                
                [_pushBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -50*Width, 0, 50*Width)];
                [_pushBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 150*Width, 0, -150*Width)];
                if(CXCWidth==320)
                {
                    [_pushBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -50*Width, 0, 50*Width)];
                    [_pushBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 170*Width, 0, -170*Width)];

                
                }
                [_pushBtn setTitleColor:TextColor forState:UIControlStateNormal];

                [_pushBtn setImage:[UIImage imageNamed:@"adress_btn_radio_sel"] forState:UIControlStateSelected];//给button添加image
                [_pushBtn setImage:[UIImage imageNamed:@"adress_btn_radio"] forState:UIControlStateNormal];//给button添加image
                _pushBtn.tag = 1999;
                [_pushBtn setTitle:@"开启推送" forState:UIControlStateNormal];//设置button的title
                _pushBtn.titleLabel.font = [UIFont systemFontOfSize:16];//title字体大小
                [bgview  addSubview:_pushBtn];
                [_pushBtn addTarget:self action:@selector(calculateTheGoods:) forControlEvents:UIControlEventTouchUpInside];
            }else if(i==2) {
                _detailLabel =leftLabe;
                _detailLabel.frame =CGRectMake(30*Width, 0, 650*Width, 0);
                _detailLabel.numberOfLines =0;
                xian.tag =12345;

            }else if(i==3) {
                _numberLabel =rightLabel;
                
            }else if(i==4) {
                _addressLabel =rightLabel;
                
            }else if(i==5) {
                _sexLabel =rightLabel;
                
            }else if(i==6) {
                _friendLabel =rightLabel;
                
            }else if(i==7) {
                bgview.backgroundColor =[UIColor whiteColor];
                
                UIButton *seeBtn =[[UIButton alloc]initWithFrame:CGRectMake(500*Width, 15*Width, 90*Width,50*Width)];
                
                [seeBtn setBackgroundColor:[UIColor whiteColor]];
                [seeBtn.layer setCornerRadius:2];
                [seeBtn.layer setBorderWidth:1];
                [seeBtn.layer setMasksToBounds:YES];
                [seeBtn setTitleColor:TextGrayColor forState:UIControlStateNormal];
                seeBtn.layer.borderColor =TextGrayColor.CGColor;
                seeBtn.tag =2000;
                [seeBtn setTitle:@"删除" forState:UIControlStateNormal];
                [seeBtn.titleLabel setTextColor:[UIColor whiteColor]];
                [seeBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
                [seeBtn addTarget:self action:@selector(examinePass:) forControlEvents:UIControlEventTouchUpInside];
                [bgview addSubview:seeBtn];
                _deletebtn =seeBtn;
                
                UIButton *circulationBtn =[[UIButton alloc]initWithFrame:CGRectMake(620*Width, 15*Width, 90*Width,50*Width)];
                [bgview addSubview:circulationBtn];
                [circulationBtn setBackgroundColor:[UIColor whiteColor]];
                [circulationBtn.layer setCornerRadius:2];
                [circulationBtn.layer setBorderWidth:1];
                [circulationBtn.layer setMasksToBounds:YES];
                [circulationBtn setTitleColor:NavColor forState:UIControlStateNormal];
                circulationBtn.layer.borderColor =NavColor.CGColor;
                circulationBtn.tag =2001;
                [circulationBtn setTitle:@"编辑" forState:UIControlStateNormal];
                [circulationBtn.titleLabel setTextColor:[UIColor whiteColor]];
                [circulationBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
                [circulationBtn addTarget:self action:@selector(examinePass:) forControlEvents:UIControlEventTouchUpInside];
                [bgview addSubview:circulationBtn];
                _editbtn  =circulationBtn;
                
            }
            if (i<3) {
                leftLabe.frame =CGRectMake(32*Width,0*Width ,650*Width , 98.5*Width);
            }
 
            
        }
        
        
    }
    return self;
    
}
- (void)examinePass:(UIButton*)btn
{
    btn.selected =YES;
    [_delegate btnClick:self andInTag:btn.tag];

}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(void)calculateTheGoods:(UIButton*)btn
{
    [_delegate btnClick:self andIsSelect:!btn.selected];
    
}
-(void)setDic:(NSDictionary *)Dict
{
    _dic =Dict;
    
    _detailLabel.text =[NSString stringWithFormat:@"%@",[_dic objectForKey:@"content"]];
    float height =[PublicMethod heightForString:[NSString stringWithFormat:@"%@",_detailLabel.text ] fontSize:14 andWidth:650*Width];
    
    _detailLabel.numberOfLines =0;
    _detailLabel.frame =CGRectMake(32*Width, 0*Width, 650*Width,height);

    UIView *view =[self viewWithTag:302];
    view.frame =CGRectMake(0,200*Width , CXCWidth,height);
    for (int i=3; i<8; i++) {
        UIView *bgView =[self viewWithTag:300+i];
        bgView.frame =CGRectMake(0,view.bottom+100*(i-3)*Width , CXCWidth, 100*Width);
    }
    UIImageView *imgV =[self viewWithTag:12345];
    imgV.frame =CGRectMake(0,_detailLabel.bottom-1.5*Width , CXCWidth, 1.5*Width);
    _timeLabel.text =[NSString stringWithFormat:@"%@",[_dic objectForKey:@"createtime"]];
    _titleLabel.text =[NSString stringWithFormat:@"%@",[_dic objectForKey:@"title"]];
    if ([[_dic objectForKey:@"num"] isEqualToString:@"0"]||[[_dic objectForKey:@"num"] isEqualToString:@""]||[[_dic objectForKey:@"num"] isEqual:[NSNull null]]) {
        _numberLabel.text =@"全部";
    }
    _numberLabel.text =[NSString stringWithFormat:@"%@",[_dic objectForKey:@"num"]];
    _addressLabel.text =[NSString stringWithFormat:@"%@",[_dic objectForKey:@"region"]];
    _sexLabel.text =[NSString stringWithFormat:@"%@",[_dic objectForKey:@"sex"]];
    _friendLabel.text =[NSString stringWithFormat:@"%@",[_dic objectForKey:@"option"]];
    _pushBtn.selected =NO;
    if ([[NSString stringWithFormat:@"%@",[_dic objectForKey:@"status"]]isEqualToString:@"2"]) {
        _statusLabel.text =@"未审核";
        _statusLabel.hidden =NO;
        _pushBtn.hidden =YES;
        _deletebtn.hidden =NO;
        _editbtn.hidden =YES;
        _deletebtn.frame =CGRectMake(620*Width, 15*Width, 90*Width,50*Width);
        
    }else
    {
        _deletebtn.hidden =NO;
        _editbtn.hidden =NO;
        _editbtn.frame =CGRectMake(620*Width, 15*Width, 90*Width,50*Width);
        _deletebtn.frame =CGRectMake(500*Width, 15*Width, 90*Width,50*Width);
        _pushBtn.hidden  =NO;
        _statusLabel.hidden =YES;
        NSLog(@"ispushwww%@",[_dic objectForKey:@"ispush"]);
        
        if ([[NSString stringWithFormat:@"%@",[_dic objectForKey:@"ispush"]]isEqualToString:@"1"]) {
            _pushBtn.selected =YES;
            
        }else if([[NSString stringWithFormat:@"%@",[_dic objectForKey:@"ispush"]]isEqualToString:@"2"])
        {
            _pushBtn.selected =NO;

        }
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


@end
